<?php
$current_datetime = date('Y-m-d H:i:s');
$current_date = date('Y-m-d');

$templates = array(
//  array(name,group,alias,parent,path)    
    array('name' => 'Master Layout','group' => 'master','alias' => 'master-layout','parent' => 0,'path' => '/layouts/'),
    array('name' => 'Blank Template','group' => '','alias' => 'blank-template','parent' => 1,'path' => '/'),
);

$sqls_insert = array(
    // pages
    "INSERT INTO public.".$user_site_prefix."page (revision_id, site_id, page_data, revised_by, creation_datetime, last_update, title, alias, status, parent_id, ordering, include_in_sitemap, allow_cache, type, route, view) VALUES ('1', '".$this->siteId."', null, null, '".$current_datetime."', '".$current_datetime."', 'Home', 'home', 't', '0', '0', 't', 'f', 'cms', null, null); ",
    "INSERT INTO public.".$user_site_prefix."page_current_revision VALUES ('1', '1', '1');",
    "INSERT INTO public.".$user_site_prefix."page_revision (creation_datetime, last_update, created_by, updated_by, log, page_id, image, template_content_id, js_files, css_files) VALUES ('".$current_datetime."', '".$current_datetime."', '1', '1', 'Init', '1', null, '2', 'array ()', 'array ()');",
    // page urls
    "INSERT INTO public.".$user_site_prefix."page_url (page_id, url, status, creation_datetime, last_update) VALUES ('1', '/', 't', '".$current_datetime."', '".$current_datetime."');",
    "INSERT INTO public.".$user_site_prefix."page_url (page_id, url, status, creation_datetime, last_update) VALUES ('1', '/index.html', 't', '".$current_datetime."', '".$current_datetime."');",
);
  
  
foreach ($templates as $key => $template) {
    $id = $key + 1;
    $templateFile = dirname(__FILE__).'/../views/'.$template['path'].$template['alias'].'.r1.php';
    // template
    $sqls_insert[] = "INSERT INTO public.".$user_site_prefix."template (name,\"group\",status,creation_datetime,last_update,revision_id,alias) VALUES ('{$template['name']}', '{$template['group']}', 't', '".$current_datetime."',null,'1','{$template['alias']}');";
    // template content
    $sqls_insert[] = "INSERT INTO public.".$user_site_prefix."template_content (template_id,revision_id,html,creation_datetime,status,css_files,js_files,log,parent_id) VALUES ({$id},'1', '". file_get_contents($templateFile) ."', '".$current_datetime."', 't', 'array()','array()','',{$template['parent']});";
    // template site
    $sqls_insert[] = "INSERT INTO public.".$user_site_prefix."template_site VALUES ({$id}, '".$this->siteId."');";
}